<?php

namespace App\Listeners;

use App\Events\AdminLogin;
use App\Models\AdminLog;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class AdminListener
{

	/**
	 * 事件订阅者
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/24 0024 14:45
	 * @param $events
	 */
	public function subscribe($events)
    {
		$events->listen(
			'App\Events\AdminLogin',
			'App\Listeners\AdminListener@createLoginLon'
		);
    }

	/**
	 * 处理登录事件
	 * User: Clannad ~ ☆
	 * DataTime：2019/11/24 0024 14:10
	 * @param $event
	 */
    public function createLoginLon($event)
    {
		$data = [
			'admin_id'=>$event->admin->id,
			'login_ip'=>$_SERVER['REMOTE_ADDR'],
			'login_time'=>date('Y-m-d H:i:s',time()),
		];

		AdminLog::create($data);

		// $email_text = $data['login_time'] . ',IP：'.$data['login_ip'] . '--' . $event->admin->nickname .'登录了账号';
		// \Mail::raw($email_text,function ($message) use ($event){
		// 	$message->to('hxxk@qq.com')->subject('【后台登录通知】' . $event->admin->nickname);
		// });
    }
}
